{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5cc96e3b",
   "metadata": {},
   "source": [
    "# Note\n",
    "非Gaming产品均未将连接LED DRIVER及PMIC的IIC的线路引出到连接器，因此无法直接通过IIC与IC进行通讯，\n",
    "只能通过IIC OVER AUX功能间接实现PMIC的通信\n",
    "\n",
    "该程序适用于TC3410 TCON + NT50805 PMIC搭配，\n",
    "对于其他TCON搭配，只需更换AUX对象，并对应修改PMIC地址"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac91c3f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "from OpticalSensor import CA410Sensor  as EyeSensor\n",
    "import time\n",
    "\n",
    "from pic_window import *\n",
    "\n",
    "import OperateCardLib"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6e2ca980",
   "metadata": {},
   "source": [
    "# VOP测试"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0ec2ba8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "462.69096\n",
      "469.20533\n",
      "474.82954\n",
      "479.61446\n",
      "483.61868\n",
      "486.99876\n",
      "489.78509\n",
      "491.97813\n",
      "493.6917\n",
      "495.04474\n",
      "496.0054\n",
      "496.60589\n",
      "496.92206\n",
      "497.00046\n",
      "496.80422\n",
      "496.42056\n",
      "495.8636\n",
      "495.12725\n",
      "494.24009\n",
      "493.27307\n",
      "492.17569\n",
      "490.95904\n",
      "489.69219\n",
      "488.35453\n",
      "486.93438\n",
      "485.52553\n",
      "484.05412\n",
      "482.61791\n",
      "481.36117\n",
      "480.37304\n"
     ]
    }
   ],
   "source": [
    "sensor = EyeSensor(port='COM13')\n",
    "\n",
    "#sensor.calibrate_sensor()\n",
    "sensor.XYZmode()\n",
    "\n",
    "# 1) 启动后立即显示一张空图，然后动态更新\n",
    "win = NonBlockingImageWindow(\"Demo\", size=(800, 800), fps=10)\n",
    "\n",
    "# # 文件路径\n",
    "# win.update(\"test.jpg\", fmt=\"path\")\n",
    "\n",
    "# RGB数据\n",
    "img = np.zeros((800, 800, 3), dtype=np.uint8)\n",
    "img[:,:,:] = 255\n",
    "win.update(img, fmt=\"rgb\")\n",
    "\n",
    "try:\n",
    "\n",
    "    dll_path = \"./OperateCardLib.dll\"\n",
    "    card_lib = OperateCardLib.Parade_TC3410(dll_path)\n",
    "\n",
    "    card_lib.init(6)\n",
    "\n",
    "\n",
    "    #GMA1 2跟随AVDD AVEE +- 0.5\n",
    "    card_lib.iic_over_aux_write(0x47, 0x0c, [0x19])\n",
    "    card_lib.iic_over_aux_write(0x47, 0x0d, [0x19])\n",
    "\n",
    "\n",
    "    y_list = []\n",
    "\n",
    "    time.sleep(2)\n",
    "    \n",
    "    #遍历AVDD/AVEEZ ±4.10~±7.0V，使VOP输出±3.6~正负6.5V\n",
    "    for i in range(0x01,0x1F,1):\n",
    "        card_lib.iic_over_aux_write(0x47, 0x03, [i*2])\n",
    "        card_lib.iic_over_aux_write(0x47, 0x04, [i])\n",
    "        time.sleep(0.2)\n",
    "        flag = True\n",
    "        while flag:\n",
    "            try:\n",
    "                x_val, y_val, z_val = sensor.GetXYZ()\n",
    "                flag = False\n",
    "            except:\n",
    "                pass\n",
    "\n",
    "        y_list.append(float(y_val))\n",
    "        print(y_val)\n",
    "\n",
    "finally:\n",
    "    win.stop()\n",
    "    del card_lib\n",
    "\n",
    "# 输出各行为对应VOP输出亮度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e237c56e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
